//   岗位页面 PostSkill   *********************** *********************** ***********************
import React, { useContext, useEffect, useState } from "react"
import { gitInterView } from "@/services/index"
import { ISkillLabel, ISkillListQuery, ISkillList } from "@/utils"
import './studentSkill.less'
import { Table, Input } from 'antd';
import { EyeOutlined, SearchOutlined } from '@ant-design/icons';
import styles from "./studentSkill.less";
import { observer } from "mobx-react-lite"
import storeContext from "@/context/storeContext";
import { Link } from "umi";


const arr = ['全部', "草稿", "已发布", '待审核', '已驳回']


const StudentSkill: React.FC = props => {
    let [skillLabel, setSkillLabel] = useState<ISkillLabel[]>([])
    let [subs, setSubs] = useState('')
    let [sub, setSub] = useState(0)
    let [queryParams, setQueryParams] = useState<ISkillListQuery>({  searchTitle: '', pageNum: 1, pageSize: 10 } as ISkillListQuery)
    let [skillList, setSkillList] = useState<ISkillList[]>()
    let [title, setTitle] = useState('');
    let [searchTitle, setSearchTitle] = useState('');
    let [stationVersionId, setStationVersionId] = useState('')//删除
    let [audit, setAudit] = useState('')//审核
    let [revocation, setRevocation] = useState('')

    let { skill } = useContext(storeContext)

    const columns = [
        {
            title: '岗位名称',
            dataIndex: 'name',
            align: "center"
        },
        {
            title: '学院',
            dataIndex: 'majorName',
            align: "center"
        },
        {
            title: '版本号',
            dataIndex: 'stationVersion',
            align: "center"
        },
        {
            title: '技能数量',
            dataIndex: 'skillNum',
            align: "center"
        },
        {
            title: '作者',
            dataIndex: 'userName',
            align: "center"
        },
        {
            title: '发起时间',
            dataIndex: 'createTime',
            align: "center"
        },
        {
            title: '操作',
            align: "center",
            render: (row: ISkillList) => {

                return <div className={styles.action}>
                    <Link to={`/teachers/addPostSkill?stationVersionId=${row.stationVersionId}&see=false`}>
                        <EyeOutlined style={{ color: '#679cf6', fontSize: "20px", padding: "0 5px" }} />
                    </Link>
                </div>
            }
        }
    ];
    // 发送请求
    useEffect(() => {
        skill.getSkillLabel()
    }, [])

    // 列表
    useEffect(() => {

        if (subs == "") {
            queryParams = { ...queryParams, majorId: "", searchTitle: title }
        } else {
            queryParams = { ...queryParams, majorId: subs, searchTitle: title }
        }

        // 数据获取
        const path="/sypt/station/selectStationNewVersionList"
        gitInterView(path,queryParams).then(ok => {
            if (ok.code == 200) {
                setSkillList(ok.rows)
            }
        })

    }, [subs, sub, searchTitle, stationVersionId, audit, revocation])

    return <div className={styles.postSkill}>
        <div className={styles.headers}>
            <div className={styles.header1}>
                <div className={styles.header_left1}>专业：</div>
                <div className={styles.header_right}>
                    <span className={subs == '' ? styles.active : ''} onClick={() => { setSubs('') }}>全部</span>
                    {
                        skill.skillLabel.map((item: { id: React.SetStateAction<string>; name: boolean | React.ReactChild | React.ReactFragment | React.ReactPortal | null | undefined; }, index: React.Key | null | undefined) => <span className={item.id == subs ? styles.active : ''}
                            onClick={(e) => { setSubs(item.id) }} key={item.id as string}>{item.name}</span>)
                    }
                </div>
            </div>
        </div>

        <div className={styles.main}>
            <div className={styles.nav}>
                <div></div>
                <span className={styles.spans}> <Input placeholder="搜索岗位" suffix={<SearchOutlined onClick={() => setSearchTitle(title)} />} value={title} onChange={e => setTitle(e.target.value)} onKeyDown={e => {
                    if (e.keyCode === 13) {
                        setSearchTitle(title)
                    }
                }} /></span>
            </div>

            <Table style={{ width: "95%", margin: "0 auto", textAlign: "center" }} rowKey="stationId" dataSource={skillList as ISkillList[]} columns={columns} />
        </div>
    </div>
}

export default observer(StudentSkill);

